{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "a308d2bd",
   "metadata": {},
   "outputs": [],
   "source": [
    "stu_info2 = dict(\n",
    "    stu10001 = \"alex\",       \n",
    "    stu10002 = \"jack\"          \n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "68068673",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "stu10001\n",
      "stu10002\n"
     ]
    }
   ],
   "source": [
    "for i in stu_info2:\n",
    "    print(i)         # 只会打印键"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "040652a0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "stu10001 alex\n",
      "stu10002 jack\n"
     ]
    }
   ],
   "source": [
    "# 循环遍历整个字典\n",
    "for k,v in stu_info2.items():\n",
    "    print(k,v)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "98d3f38e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 实践1：筛出键中的数字，作为新键，新建字典"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "7684ea53",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'10001': 'alex', '10002': 'jack'}"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new = {}\n",
    "for k,v in stu_info2.items():\n",
    "    # 用字典新增的方式创建字典\n",
    "    new[k[3:]] = v \n",
    "new"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4b97b45d",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 实践2： 改值：变为大写"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "b4f84624",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'10001': 'ALEX', '10002': 'JACK'}"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "for k,v in stu_info2.items():\n",
    "    new[k[3:]] = v.upper()\n",
    "new"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "21582047",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{10001: 'ALEX', 10002: 'JACK'}"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_info = {}\n",
    "# 实践3： 让key变为整数\n",
    "for k,v in stu_info2.items():\n",
    "    new_info[int(k[3:])] = v.upper()\n",
    "new_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fd45f08d",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
